package org.mxp.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
public class TableMessageService {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public int add(String data) {
        int insert = jdbcTemplate.update("insert into table_message_data (id, data, create_date) values (?, ?, ?)", UUID.randomUUID().toString(), data, new Date());
        return insert;
    }

    public List<Map<String, Object>> list() {
        List<Map<String, Object>> list = jdbcTemplate.queryForList("select * from table_message_data");
        return list;
    }

    public Map<String, Object> lastInfo() {
        Map<String, Object> info = jdbcTemplate.queryForMap("select * from table_message_data order by create_date desc limit 1");
        return info;
    }
}
